package com.bjpowernode.util;

import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * 工具类
 */
public class ResponseUtil {

    public static void write(HttpServletResponse response, String result) {
        //设置响应编码
        response.setCharacterEncoding("UTF-8");
        //设置响应内容类型(媒体类型)
        response.setContentType("application/json;charset=utf-8");

        //响应写出去
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.write(result);
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }
}
